<?php

autoLoader();

$objWard 		= new Wards();
$arrobjWards 	= $objWard->fetchAllWards();

$arrobjWardCatagories = new WardCatagories();
$arrobjWardCatagories = $arrobjWardCatagories->fetchAllWardCatagories();
$arrobjWardCatagories = rekeyObjects( 'Id', $arrobjWardCatagories );

$arrobjWardTypes = new WardTypes();
$arrobjWardTypes = $arrobjWardTypes->fetchAllWardTypes();
$arrobjWardTypes = rekeyObjects( 'Id', $arrobjWardTypes );

// display( $arrobjPatients ); exit;

if( false == valArr( $arrobjWards ) ) {
	echo '<h2>Wards are not avaliable.</h2>';
} else {
?>
<link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
<script src="js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>
<script src="js/bootstrap-confirmation.js" type="text/javascript"></script>
<script>
	$(document).ready(function() {
		$('#dataTables-example').dataTable();
	});
</script>
<script>
function DeleteData(id){
               var r = confirm("Are You Sure Delete This Ward?");
               if (r==true){
                  $.ajax({
                     type: "POST",
                     url: "modules.php?file=delete_wards",
                     data:{did:id},
                     beforeSend : function () {
                     },
                     success:function(){
					 location.reload();
                     }
                  });
               }else{   
               }
            }
</script>
<style>
	.thclass{
	font-size:12px;
	}
	.tbclass{
	font-size:12px;
	}
</style>

	<div style="margin-left:12px; margin-top: 10px;">
		<p>
			<a class="btn btn-outline btn-primary btn-xs" id="act" href="modules.php?file=wards&mid=<?php echo $mid;?>&smid=<?php echo $smid;?>" >Add New Ward</a>
			<a class="btn btn-outline btn-primary btn-xs" id="active" href="modules.php?file=view_wards&type=view&mid=<?php echo $mid;?>&smid=<?php echo $smid;?>" >View All Wards</a>&nbsp;
		</p>
	</div>
	
<div class="col-lg-12">
	<div class="panel panel-primary">
		
		<div class="panel-heading"><i class="fa fa-bell fa-fw"></i>Wards List</div>
		<div class="panel-body">
			<div class="table-responsive">
				<table class="table table-striped table-bordered table-hover" id="dataTables-example">
					<thead class="thclass">
						<tr>
							<th>Sr.No</th>
							<th>Room Number</th>
							<th>Ward Type</th>
							<th>Ward Catagory</th>
							<th>Rate</th>
							<th>patient</th>
							<th>Reporting Doctor</th>
							<th>Reservation Id</th>
							<th>Edit</th>
							<th>Delete</th>
					</thead>
					<tbody class="tbclass">
					<?php 
						$intSnCount = 1;
						foreach( $arrobjWards as $objWard ) {
					?>
							<tr class="odd gradeX">
							<td><?php echo $intSnCount; ?></td>
							<td><?php echo $objWard->getRoomNumber(); ?></td>
							<td><?php $objWardType = getArrayElementByKey( $objWard->getWardTypeId(), $arrobjWardTypes ); echo ( true == valObj( $objWardType, 'BaseWardTypes' ) ) ? $objWardType->getName() : NULL;?></td>
							<td><?php $objWardCatagory = ( ( true == valObj( $objWardType, 'BaseWardTypes' ) ) ? getArrayElementByKey( $objWardType->getWardCatagoryId(), $arrobjWardCatagories ) : NULL ); echo ( ( true == valObj( $objWardCatagory, 'BaseWardCatagories' ) ) ? $objWardCatagory->getName() : NULL ); ?>
							<td><?php echo $objWard->getRate(); ?></td>
							<td><?php echo $objWard->getPatientId(); ?></td>
							<td><?php echo $objWard->getReportingDoctorId(); ?></td>
							<td><?php echo $objWard->getReservationId(); ?></td>
							<td>
								<a href="modules.php?file=wards&ward_id=<?php echo $objWard->getId(); ?>&mid=<?php echo $mid;?>&smid=<?php echo $smid;?>" title="Update patient information"><img src="images/icons/update.png" width="25" height="25"></a>
							</td>
							<td>
								<a id="delete_ward" onClick="DeleteData(<?echo $objWard->getId();?>);"><img src="images/icons/delete.jpg" width="25" height="25"></a>
							</td>
							</tr>
					<?php
					} 
					?>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<?php
}
?>